//
//  ViewController.m
//  CYTest
//
//  Created by Rain on 16/6/21.
//  Copyright © 2016年 Rain. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UITextField *condition;

@property (weak, nonatomic) IBOutlet UITextField *tem;

@end

@implementation ViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    _KYNet=[CYNet getInstance];
    //得到单例
    _KYNet.delegate=self;
    //将KYNet的代理与ViewController连接
}

//北京按钮
- (IBAction)beijingTouched:(id)sender
{
    [_KYNet getWeatherWithCityName:@"Beijing"];
}

//上海按钮
- (IBAction)shanghaiTouched:(id)sender
{
    [_KYNet getWeatherWithCityName:@"Shanghai"];
}

#pragma mark -
-(void)getWeatherInfoSuccessFeedback:(id)feedbackInfo{
    //当服务器返回成功数据后，下列代码被激活
    NSLog(@"%@",[feedbackInfo class]);
    
    NSDictionary *dic=feedbackInfo;
    
    NSArray *weather1=[dic objectForKey:@"weather"];
    
    NSDictionary *main1=[dic objectForKey:@"main"];
    
    NSDictionary *weather=[weather1 objectAtIndex:0];
    
    NSString *temp=[NSString stringWithFormat:@"%@",[main1 objectForKey:@"temp"]];
    
    NSString *weatherInfo=[NSString stringWithFormat:@"%@",[weather objectForKey:@"description"]];
    
    _condition.text=weatherInfo;
    
    _tem.text=temp;
}

-(void)getWeatherInfoFailFeedback:(id)failInfo{
    
    NSLog(@"%@",failInfo);
}

@end
